<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>ComObjType()</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>ComObjType() <span class="ver">[v1.0.91+]</span></h1>

<p>Retrieves type information from a COM object.</p>

<pre class="Syntax">VarType := ComObjType(ComObject)
Name    := ComObjType(ComObject, "Name")
IID     := ComObjType(ComObject, "IID")</pre>

<h3>Parameters</h3>
<dl>

  <dt>ComObject</dt>
  <dd><p>A wrapper object containing a COM object or typed value.</p></dd>

  <dt>VarType</dt>
  <dd><p>An integer indicating the type of value. See below.</p></dd>

  <dt>Name</dt>
  <dd><p>An interface type name.</p></dd>

  <dt>IID</dt>
  <dd><p>A globally unique identifier (GUID) representing the interface type.</p></dd>

</dl>

<h3>Return Value</h3>
<p>If the second parameter is omitted, the variant type of the value contained by the wrapper object is returned.</p>
<p>If the second parameter is "Name" or "IID" and the wrapper object contains a COM object (variant type VT_DISPATCH), the COM object's type name or the identifier of its primary interface is returned.</p>
<p>In the parameters are invalid or an error occurs, an empty string is returned.</p>

<h3 id="vt">Variant Type Constants</h3>
<pre>
VT_EMPTY     =      0  <em>; No value</em>
VT_NULL      =      1  <em>; SQL-style Null</em>
VT_I2        =      2  <em>; 16-bit signed int</em>
VT_I4        =      3  <em>; 32-bit signed int</em>
VT_R4        =      4  <em>; 32-bit floating-point number</em>
VT_R8        =      5  <em>; 64-bit floating-point number</em>
VT_CY        =      6  <em>; Currency</em>
VT_DATE      =      7  <em>; Date</em>
VT_BSTR      =      8  <em>; COM string (Unicode string with length prefix)</em>
VT_DISPATCH  =      9  <em>; COM object</em>
VT_ERROR     =    0xA  <em>; Error code (32-bit integer)</em>
VT_BOOL      =    0xB  <em>; Boolean True (-1) or False (0)</em>
VT_VARIANT   =    0xC  <em>; <a href="http://msdn.microsoft.com/en-us/library/ms221627.aspx">VARIANT</a> (must be combined with VT_ARRAY or VT_BYREF)</em>
VT_UNKNOWN   =    0xD  <em>; IUnknown interface pointer</em>
VT_DECIMAL   =    0xE  <em>; (not supported)</em>
VT_I1        =   0x10  <em>; 8-bit signed int</em>
VT_UI1       =   0x11  <em>; 8-bit unsigned int</em>
VT_UI2       =   0x12  <em>; 16-bit unsigned int</em>
VT_UI4       =   0x13  <em>; 32-bit unsigned int</em>
VT_I8        =   0x14  <em>; 64-bit signed int</em>
VT_UI8       =   0x15  <em>; 64-bit unsigned int</em>
VT_INT       =   0x16  <em>; Signed machine int</em>
VT_UINT      =   0x17  <em>; Unsigned machine int</em>
VT_RECORD    =   0x24  <em>; User-defined type -- NOT SUPPORTED</em>
VT_ARRAY     = 0x2000  <em>; <a href="http://msdn.microsoft.com/en-us/library/ms221482.aspx">SAFEARRAY</a></em>
VT_BYREF     = 0x4000  <em>; Pointer to another type of value</em>
<em>/*
 VT_ARRAY and VT_BYREF are combined with another value (using bitwise OR)
 to specify the exact type. For instance, 0x2003 identifies a <a href="http://msdn.microsoft.com/en-us/library/ms221482.aspx">SAFEARRAY</a>
 of 32-bit signed integers and 0x400C identifies a pointer to a <a href="http://msdn.microsoft.com/en-us/library/ms221627.aspx">VARIANT</a>.
*/</em>
</pre>

<h3>General Remarks</h3>
<p>In most common cases, return values from methods or properties of COM objects are converted to an appropriate data type supported by AutoHotkey. Types which aren't specifically handled are coerced to strings via <a href="http://msdn.microsoft.com/en-us/library/ms221258.aspx">VariantChangeType</a>; if this fails or if the variant type contains the VT_ARRAY or VT_BYREF flag, an object containing both the value and its type is returned instead.</p>
<p>For any variable <i>x</i>, if <code>ComObjType(x)</code> returns an integer, <i>x</i> contains a COM object wrapper.</p>


<h3>Related</h3>
<p><a href="ComObjValue.htm">ComObjValue</a>, <a href="ComObjCreate.htm">ComObjCreate</a>, <a href="ComObjGet.htm">ComObjGet</a>, <a href="ComObjActive.htm">ComObjActive</a></p>

<h3>Examples</h3>
<pre class="NoIndent">
d := <a href="ComObjCreate.htm">ComObjCreate</a>("Scripting.Dictionary")
VarType := ComObjType(d)          <em>; Always 9 for script-callable objects.</em>
Name    := ComObjType(d, "Name")  <em>; Only valid for script-callable objects.</em>
IID     := ComObjType(d, "IID")   <em>; As above.</em>
MsgBox Variant type:`t%VarType%`nType name:`t%Name%`nInterface ID:`t%IID%
</pre>

</body>
</html>
